package com.tencent.wxcloudrun.util;

import org.redisson.api.RLock;
import org.redisson.api.RReadWriteLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author ZhaoZiYin
 * @Date 2025/4/27
 * @Description Redis分布式锁工具类
 */
@Component
public class RedissonUtil {

    @Resource
    private RedissonClient redissonClient;

    public RLock getClint(String key){
        RReadWriteLock lock = redissonClient.getReadWriteLock(key);
        return lock.writeLock();
    }

    public void lock(String key) {
        this.getClint(key).lock();
    }

    public void unLock(String key) {
        this.getClint(key).unlock();
    }
}
